#include "JSONData.h"
#include <iosfwd>

// Let say x is a JSON_Value Object,
// then if JSON_Type is JSON_OBJECT, then
// JSON_Object * jo = (JSON_Object)x.data;

int main()
{
	//char testC[5] = "abcd";
	//wchar_t test[2];
	//memcpy(test, testC, 5);
	//char* test2 = (char*)test;

	simframework::json::JSON_Object jo(L"   { \t\"name\" : \"value\", \"age\" : { \"A\" : [\"50\", \"B\" , \"20\"] } , \"pp\" : \"oo\"} ");
	simframework::json::JSON_Object kk(L"{ \"A\" : \"10\", \"B\" : \"20\" }");
	simframework::json::JSON_Object mm(L" { \"A\" : [\"aaa\",\"bbbEE\"] } ");

	simframework::json::JSON_Array * a = mm.getArrayValueByKey(L"A");
	std::wcout << "val = " << a->getStringValueForId(1) << std::endl;

	simframework::json::JSON_Object * j = jo.getObjectValueByKey(L"age");
	if (j)
	{
		simframework::json::JSON_Array * a = j->getArrayValueByKey(L"A");
		if (a)
		{
			std::wcout << a->getStringValueForId(2) << std::endl;
		}
	}

	std::wstring test1 = L"{ \
		\"glossary\": { \
			\"title\": \"example glossary\", \
			\"GlossDiv\": { \
				\"title\": \"S\", \
				\"GlossList\": { \
					\"GlossEntry\": { \
						\"ID\": \"SGML\", \
						\"SortAs\": \"SGML\", \
						\"GlossTerm\": \"Standard Generalized Markup Language\", \
						\"Acronym\": \"SGML\", \
						\"Abbrev\": \"ISO 8879:1986\", \
						\"GlossDef\": { \
							\"para\": \"A meta-markup language, used to create markup languages such as DocBook.\", \
							\"GlossSeeAlso\": [\"GML\", \"XML\"] \
						}, \
						\"GlossSee\": \"markup\" \
					} \
				} \
			} \
		} \
	}";

	simframework::json::JSON_Object a1(test1);
	simframework::json::JSON_Array * arr = a1.getObjectValueByKey(L"glossary")->
		getObjectValueByKey(L"GlossDiv")->getObjectValueByKey(L"GlossList")->
		getObjectValueByKey(L"GlossEntry")->getObjectValueByKey(L"GlossDef")->getArrayValueByKey(L"GlossSeeAlso");

	std::wcout << arr->getStringValueForId(1) << std::endl;
	std::wcout << arr->getStringValueForId(1) << std::endl;

	simframework::json::JSON_Object jsonobj(L" { \"A\" => \"ggg\" } ");
	std::wcout << jsonobj.getStringValueByKey(L"A") << std::endl;

	//JSON_Abstract * ak = kk.getValueForKey("B");
	//if (ak) std::cout << "AK = " << ak->getValueAsString() << std::endl;
	//JSON_Abstract * ab1 = jo.getValueForKey("name");
	//JSON_Abstract * ab2 = jo.getValueForKey("age");
	//if (ab1)
	//{
	//	std::cout << "name => " << ab1->getValueAsString() << std::endl;
	//}
	//if (ab2)
	//{
	//	JSON_Object * jobj = (JSON_Object*)ab2;
	//	JSON_Abstract * pp = jobj->getValueForKey("B");
	//	
	//	if (pp) std::cout << "B => " << pp->getValueAsString() << std::endl;
	//}

	//JSON_Array jarr ("[ \"ddd\", \"ffff\" ]");
	//std::cout << jarr.getElementCount() << std::endl;
	//JSON_Object * param = (JSON_Object *)jo.getValue("param");
	//JSON_String * param2 = (JSON_String *)param->getValue("param2");
	//std::string strValue = param2->str();
	//JSON_Array * param3 = (JSON_Array *)param->getValue("param3");
	//JSON_Number * num = (JSON_Number *)param3->getValue(0);
	//float number = num->number();

	return 0;
}